import React, { useRef, useState, useEffect } from "react";
function Example8() {
  const inputEl = useRef(null);
  const onButtonClick = () => {
    inputEl.current.value = "hello, fatejian";
    console.log(inputEl);
  };
  const [text, setText] = useState("fatejian");
  const textRef = useRef();
  useEffect(() => {
    textRef.current = text;
    console.log("textRef.current:", textRef.current);
  });
  return (
    <>
      <input ref={inputEl} type="text"></input>
      <button onClick={onButtonClick}>在input上展示文字</button>
      <input
        value={text}
        type="text"
        onChange={(e) => {
          setText(e.target.value);
        }}
      ></input>
    </>
  );
}
export default Example8;
